package com.koron.ticket.operation.mapper;

import com.koron.ticket.operation.bean.AppUserBean;
import com.koron.ticket.operation.bean.OperationTicketBean;
import com.koron.ticket.operation.bean.dto.OperationTicketQueryDto;
import com.koron.ticket.operation.bean.dto.OperationTicknNewsDto;
import com.koron.ticket.operation.bean.excelbean.InspectAppOrg;
import com.koron.ticket.operation.bean.excelbean.InspectStaffandDept;
import com.koron.ticket.spotcheck.bean.OperSpotBo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface OperationTicketMapper {

    int deleteByPrimaryKey(String id);

    int insert(OperationTicketBean record);

    int insertSelective(OperationTicketBean record);

    OperationTicketBean selectByPrimaryKey(String id);

    int updateByPrimaryKeySelective(OperationTicketBean record);

    int updateByPrimaryKey(OperationTicketBean record);

    @Select(" select case when max(RIGHT(code,2)) is null then '00' else max(RIGHT(code,2)) end " +
            " from w_ticket_operation where `type` = #{type} and left(CREATE_TIME,10)=left(now(),10) and status != -1 and delete_flag != 1")
    String maxOrderNo(String type);

    int maxNo(@Param(value = "workCode") String workCode, @Param(value = "type")String type);

    int maxNoByYear(@Param(value = "type")String type, @Param(value = "year") Integer year);

//    int workUpdateCheckResultsById(@Param("updatedDeleteFlag") Integer updatedDeleteFlag, @Param("id") String id);
    int updateDeleteFlagById(OperationTicketBean record);

    //列表
    List<OperationTicketQueryDto> queryList(OperationTicketQueryDto vo);

    //jzp 通讯接口
    List<OperationTicketQueryDto> queryListNoPage(OperationTicknNewsDto vo);

    //更新单据状态
    int updateStatusById(@Param("updatedStatus") Integer updatedStatus, @Param("id") String id);

    //自审回填自审人信息
    int updateCheckerAndCheckerNameById(@Param("updatedChecker") String updatedChecker, @Param("updatedCheckerName") String updatedCheckerName, @Param("id") String id);

    //查人员部门对应关系
    @Select(" select a.id as staffId,a.account,a.name as staffName,b.id as deptId,b.code as daptCode,b.name as daptName\n" +
            "from s_group_staff a\n" +
            "join s_group_department b on b.code = a.department ")
    List<InspectStaffandDept> queryStaffandDept();

    @Select(" select * from s_app_org ")
    List<InspectAppOrg> queryAppOrg();

    //根据账号查用户
    @Select(" select name,account,password from s_app_user where account = #{account} ")
    AppUserBean queryUserByAcc(String account);

    int updateCodeById(@Param("updatedCode")String updatedCode,@Param("id")String id);

    List<OperSpotBo> queryAllEffective(@Param("startTime") Date startTime, @Param("endTime")Date endTime);

}
